<template>
  <div class="app-container">
    <el-form :model="queryParams" @submit.native.prevent ref="queryForm" size="small" :rules="rules" :inline="true"
      label-width="90px" style="display: flex; justify-content: center">
      <el-form-item class="item-class" label="" prop="keyWord">
        <el-input v-model="queryParams.keyWord" placeholder="支持工单编号、SN码、物料序列号" clearable
          @keyup.enter.native="handleQuery" style="width: 350px" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
      </el-form-item>
    </el-form>
    <div v-show="resultType" v-loading="loading">
      <div v-show="resultType === 'workOrder'" class="title">
        工单编号: {{ workOrderCode }}
      </div>
      <div v-show="resultType === 'item'" class="title">
        物料序列号: {{ itemCode }}
      </div>
      <div v-show="resultType === 'snCode'" class="title">
        sn码: {{ snCode }}
      </div>
      <OrderTrace ref="OrderTrace"></OrderTrace>
    </div>
  </div>
</template>
<script>
import { getFromQuery } from "@/api/mes/pro/compreTrace.js";
import OrderTrace from "./index1.vue";
import OrderTrace2 from "./index2.vue";
import OrderTrace3 from "./index3.vue";

export default {
  name: "CompreTrace",
  components: { OrderTrace, OrderTrace2, OrderTrace3 },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 查询参数
      queryParams: {
        keyWord: null,
      },
      workOrderCode: null,
      itemCode: null,
      snCode: null,
      resultType: "",
      formData: {},
      rules: {
        keyWord: [
          { required: true, message: '请填写工单编号、SN码或者物料序列号', trigger: 'blur' }
        ]
      }
    };
  },
  created() { },
  methods: {
    reset() {

    },
    /** 查询设备维修列表 */
    getList() {
      this.loading = true
      console.log(this.queryParams);
      getFromQuery(this.queryParams)
        .then((res) => {
          this.loading = false
          console.log(111, res);
          this.resultType = res.resultType;
          this.snCode = res.data.snCode;
          this.workOrderCode = res.data.workOrderCode;
          this.itemCode = res.data.itemCode
          const data = res.data ? res.data : {};
          this.$refs.OrderTrace.init(data, this.resultType);
        })
        .catch((err) => {
          this.loading = false
          console.log(123, err)
          this.resultType = "";
        });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.$refs['queryForm'].validate((valid) => {
        if (valid) {
          this.getList();
        } else {
          return false;
        }
      });

    },
  },
};
</script>
<style scoped>
.title {
  font-size: 20px;
  background: #4ec4c5;
  padding: 10px;
  color: #fff;
  text-align: center;
}
</style>
